<template>
  <div>
    <!-- 面包导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/admin' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>图书管理</el-breadcrumb-item>
      <el-breadcrumb-item>图书列表</el-breadcrumb-item>
      <el-breadcrumb-item>添加章节</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
     
     <el-form  :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="70px">
        <el-form-item prop="namebook">
          <el-input
          type="textarea"
          :rows="16"
          placeholder="请输入内容"
          v-model="addForm.namebook" style="margin-top:2rem">
        </el-input>
        </el-form-item>
          <el-button type="primary"  style="margin-left:5rem" @click="onSubmit">确 定</el-button>
      </el-form>

  </div>
</template>    

<script>
import { setToken, setUserName } from "../../utils/auth";
import request from "../../utils/request";
export default {
  data(){
    return{
      id: '',
        //添加图书的表单数据
      addForm:{
        namebook:''
     },
         //添加表单的验证规则对象
        addFormRules:{
          namebook:[
            { required: true, message: '请输入章节内容', trigger: 'blur' },
            { min: 23, max: 500, message: '长度在 23 到 500 个字符', trigger: 'blur' }
          ]
        }
      }
    },

  created() {
    this.getBookadd()
  },
  methods: {
    //添加章节跳转
    getBookadd(index){
      let time = this.$route.query.id;
      this.id = time
    },
     //添加图书
    onSubmit() {
       var day = new Date();
       var time=day.toLocaleString(); //获取当前时间
      const params = {
        namebook:this.addForm.namebook,
        bookid:this.id
     }
      request({
        url: "/api/user/addbooksadd",
        method: "post",
        data: params
      }).then(res => {
        if (res.msg === "新增成功") {
          this.$message({
            message: "恭喜你，新增成功",
            type: "success"
          });
          this.$router.push("/admin/welcome");
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
</style>